# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models

# Create your models here.

class Category(models.Model):
    """
    博客分类
    """
    name = models.CharField('名称',max_length=30)

    def __unicode__(self):
        return self.name

class Tag(models.Model):
    """
    博客标签
    """
    name = models.CharField('名称',max_length=16)

    def __unicode__(self):
        return self.name

class Article(models.Model) :
    """
    博客
    """
    title = models.CharField('标题',max_length=100)
    author = models.CharField('作者',max_length=16,default='Qin Jin')
    content = models.TextField('博客正文',blank = True, null = True)
    date_time = models.DateTimeField('发布时间',auto_now_add=True)
    category = models.ForeignKey(Category,verbose_name='分类',max_length = 50, blank = True,default=1)
    tags = models.ManyToManyField(Tag,verbose_name='标签')

    #python2使用__unicode__, python3使用__str__
    def __unicode__(self) :
        return self.title

    class Meta:  #按时间下降排序
        ordering = ['-date_time']

class Comment(models.Model):
    """
    评论
    """
    blog = models.ForeignKey(Article,verbose_name='博客')
    name = models.CharField('称呼',max_length=16)
    email = models.EmailField('邮箱')
    content = models.CharField('内容',max_length=240)
    created = models.DateTimeField('发布时间',auto_now_add=True)

    def __unicode__(self):
        return self.content
